/* useReducer  ---vuex */
import { useReducer } from "react";
const useMyReducer=()=>{
    /* 相当于vuex state */
    const initState={
        count:0
    }
    const reducer =(state,action)=>{
        /* action---vuex的actions */
        /* switch(action.type){
            case "increase":
                return {
                    count:state.count+1
                }
            case "decrease":
                return {
                    count :state.count-1
                }    
                default:
                    return initState;
        } */
        if(action.type==="increase"){
            return{ 
                count:state.count+1
            }
        }
        if(action.type==="decrease"){
            return{ 
                count:state.count-1
            }
        }
    }
    /* dispatch相当于vuex dispatch */
    const [state,dispatch] = useReducer(reducer,initState);
    return [state,dispatch]
}
export default useMyReducer;